package org.nf.box.common.exception;


import lombok.extern.slf4j.Slf4j;
import org.nf.box.common.result.ResultVO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author lzp
 * @Date 2024-11-26
 */
@RestControllerAdvice("org.nf.box.web")
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(GlobalException.class)
    public <T> ResultVO<T> handleGlobalException(GlobalException e) {
        log.error(e.getMessage(), e);
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(e.getErrorCode());
        resultVO.setMessage(e.getMessage());
        return resultVO;
    }

    @ExceptionHandler(Exception.class)
    public <T> ResultVO<T> handleException(Exception e) {
        log.error(e.getMessage(), e);
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(500);
        resultVO.setMessage("服务器内部错误");
        return resultVO;
    }
}
